package com.atguigu.day20.syn01.smethod1;
//todo 账户类
public class Account {
    int money = 2000;

    /**
     * 取钱
     * @param money
     */
    public void  withDraw(int money){
        this.money-=money;
    }
    public synchronized void takeMoney() {//this
        //1.校验余额
        if (this.money >= 1500) {

            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //2.满足 取钱
            this.withDraw(1500);
            System.out.println(Thread.currentThread().getName() + "取钱成功,余额是" + money + "元");
        } else {
            //3.不满足 提示信息 余额不足
            System.out.println(Thread.currentThread().getName() + "取钱失败 余额不足,余额是" + money + "元");
        }
    }
}
